<?php
defined('IN_ADMIN') or exit('No permission resources.');
include $this->admin_tpl('header','admin');
?>
<style>
th { font-weight:normal; padding:5px 0 5px 0;}
</style>
<form action="?m=ushop&c=bonus&a=bonus_orderby&type=0&menuid=<?php echo $_GET['menuid'];?>" method="post" id="sale_form">
<div class="table-list" style="width:99%; margin:auto;">
<table width="100%" cellspacing="0">
	<thead>
		<tr>
			<th width="15%" align="center">编号&nbsp;
                <a href="javascript:alse_sort('bonus_id','desc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_desc.gif" /></a>&nbsp;
                <a href="javascript:alse_sort('bonus_id','asc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_asc.gif" /></a>
            </th>
			<th width="15%" align="center">红包类型&nbsp;
                <a href="javascript:alse_sort('bonus_type_id','desc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_desc.gif" /></a>&nbsp;
                <a href="javascript:alse_sort('bonus_type_id','asc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_asc.gif" /></a>
            </th>
			<th width="13%" align="center">订单号&nbsp;
                <a href="javascript:alse_sort('order_id','desc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_desc.gif" /></a>&nbsp;
                <a href="javascript:alse_sort('order_id','asc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_asc.gif" /></a>
            </th>
			<th width='15%' align="center">使用会员&nbsp;
                <a href="javascript:alse_sorttype('user_id0')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_desc.gif" /></a>&nbsp;
                <a href="javascript:alse_sorttype('user_id1')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_asc.gif" /></a>
            </th>
            <th width='15%' align="center">使用时间&nbsp;
                <a href="javascript:alse_sort('used_time','desc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_desc.gif" /></a>&nbsp;
                <a href="javascript:alse_sort('used_time','asc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_asc.gif" /></a>
            </th>
            <th width='15%' align="center">邮件通知&nbsp;
                <a href="javascript:alse_sort('emailed','desc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_desc.gif" /></a>&nbsp;
                <a href="javascript:alse_sort('emailed','asc')"><img src="<?php echo IMG_PATH ;?>admin_img/sort_asc.gif" /></a>
            </th>
            <input type="hidden" name="sale_order" value="" id="sale_order" />
            <input type="hidden" name="orderby" value="<?php echo array2string($where); ?>" />
            <input type="hidden" name="orderby_member" value="" id="orderby_member" />
            <th width="15%" align="center">操作</th>
		</tr>
	</thead>
<tbody>
<?php
if(is_array($infos) && !empty($infos)){
	foreach($infos as $info){
?>
	<tr>
        <th width="15%" align="center"><input type="checkbox" name="mid[]" value="<?php echo $info['bonus_id']?>"><?php echo $info['bonus_id']; ?></th>
        <th width="15%" align="center"><?php echo $info['title'] ?></th>
        <th width="13%" align="center"><?php if(!$info['bonus_sn']==0) {echo $info['bonus_sn'];} ?></th>
        <th width='15%' align="center"><?php echo $info['member'] ?></th>
        <th width="13%" align="center"><?php if($info['used_time'] == 0) {echo '未使用';}else{echo date('Y-m-d H:m:s',$info['used_time']);} ?></th>
        <th width="14%" align="center"><?php if($info['emailed'] == 0) {echo '未发送';}else{echo '已发送';}?></th>
        <th width="15%" align="center">
			<?php if($info['emailed'] == 1) { ?>
				已发送&nbsp;
			<?php }else{?>
				<a href="#" onclick="javascript:send_email('<?php echo $info['bonus_id'];?>','<?php echo $info['user_id']; ?>');">发送邮件</a>&nbsp;
			<?php }?>
            <a href="?m=ushop&c=bonus&a=bonus_delete&mid=<?php echo $info['bonus_id']; ?>">移除</a>&nbsp;
        </th>
	</tr>
<?php
	}
}else if(empty($infos)) {
?>
	<tr>
    	<td colspan="7" align="center">没有找到任何记录</td>
    </tr>
<?php	
}
?>
</tbody>
</table>
</div>
<div class="btn">
    <a href="#" onClick="javascript:$('input[type=checkbox]').attr('checked', true)"><?php echo L('selected_all')?></a>/
    <a href="#" onClick="javascript:$('input[type=checkbox]').attr('checked', false)"><?php echo L('cancel')?></a>
    <input name="dosubmit" type="submit" class="button" value="删除选中" onclick="return confirm('<?php echo L('confirm', array('message' => L('selected')))?>');">&nbsp;&nbsp;
</div>
<div id="pages"><?php echo $pages?></div>
</form>
<script>
	$("input[value='删除选中']").live('mousedown',function() {
		document.getElementById("sale_form").action = "?m=ushop&c=bonus&a=bonus_delete";
	})
	function send_email(id,userid) {
		$.get('http://www.eshop.com/index.php?m=ushop&c=bonus&a=public_send_email&mid='+id+'&user_id='+userid,function() {alert('激活成功')});
	}
	function alse_sort(sort_by,sort_order) {
		document.getElementById('sale_order').value = sort_by+'&'+sort_order;
		document.getElementById('sale_form').submit();
	}
	function alse_sorttype(sort_by) {
		document.getElementById('orderby_member').value = sort_by;
		document.getElementById('sale_form').submit();
	}
</script>
</body>
</html>